using System;
using Scenario.WorkflowEngine.DataModel;

namespace Scenario.WorkflowEngine.DataModel.WorkflowRelevantData
{
	//*********************************************************************
	//
	// Variable Class
	//
	// The XmlVariable class represents a Process or Activity attribute
	// witch contains or values to use like chosen parameter or parameters
	// name to evaluate by idioma language
	//
	//*********************************************************************

	public class XMLAttribute : bOS.XML.Data.XMLObject 
	{
		public const string MAIN_NODE				= "Attribute";

		public const string NAME_ATTRIBUTE			= "Name";
		public const string TYPE_ATTRIBUTE			= "Type";
		public const string DIRECTION_ATTRIBUTE		= "Direction";

		public const string VALUE_NODE				= "Value";

		public const string XML_TYPE				= "XML";
		public const string STRING_TYPE				= "STRING";

		public const string DIRECTION_NONE			= "NONE";
		public const string DIRECTION_INPUT			= "INPUT";
		public const string DIRECTION_OUTPUT		= "OUTPUT";
		public const string DIRECTION_INPUTOUTPUT	= "INPUTOUTPUT";
		public const string DIRECTION_CONSTANT		= "COSTANT";
		public const string DIRECTION_TASK			= "TASK";
		public const string DIRECTION_NOTMIGRATE	= "NOTMIGRATE";


		/** FIELDS **/

		private string sName;
		private string sDirection;
		private string sType;
		private string sValue;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple Property **/
		public XMLAttribute()
		{
			this.Init();
		}

		public XMLAttribute(string _Name, string _Type, string _Direction)
		{
			this.Init();

			sName = _Name;
			sType = _Type;
			sDirection = _Direction;
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLAttribute(System.Xml.XmlNode attribute)
		{
			this.Parse(attribute);
		}

		/** PROPERTIES **/


		public string Name 
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Type 
		{
			get { return sType; }
			set { sType = value; }
		}

		public string Direction 
		{
			get { return sDirection; }
			set { sDirection = value; }
		}

		public string Value 
		{
			get { return sValue; }
			set { sValue = value; }
		}


		/** INSTANCE METHODS **/

		/** Inizializing method **/
		public override void Init()
		{
			sName= string.Empty;
			sDirection= string.Empty;
			sType= string.Empty;
			sValue= string.Empty;
		}

		/** Parsering method for filling the attribute **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLAttribute.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;
					case XMLAttribute.TYPE_ATTRIBUTE:
						sType = node.InnerText;
						break;
					case XMLAttribute.DIRECTION_ATTRIBUTE:
						sDirection = node.InnerText;
						break;
				}
			}

			/** find the sub tags witch contains values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch ( node.Name )
				{
					case XMLAttribute.VALUE_NODE:
						if ( sType == XMLAttribute.XML_TYPE) 
						{
							sValue = node.InnerXml; 
						}
						else
						{
							sValue = node.InnerText; 
						}
						break;
				}
			}
		}

		/**Method to retive a node from object **/
		override public bOS.XML.XMLNode GetXMLNode()
		{
			bOS.XML.XMLNode xmlNode = new bOS.XML.XMLNode(XMLAttribute.MAIN_NODE, "");
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute (XMLAttribute.NAME_ATTRIBUTE, sName) );
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute (XMLAttribute.TYPE_ATTRIBUTE, sType) );
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute (XMLAttribute.DIRECTION_ATTRIBUTE, sDirection) );

			xmlNode.AddNode ( new bOS.XML.XMLNode ( XMLAttribute.VALUE_NODE, sValue) );
			
			return xmlNode;
		}

		/** STATIC METHODS **/

		/** no static methods **/
	}
}